package com.liao.ticket.common.handler;

import com.liao.ticket.common.exception.BaseException;
import com.liao.ticket.vo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//对加了@Controller注解的方法进行拦截处理 AOP实现
@RestControllerAdvice
public class AllExceptionHandler {

    // 进行异常处理，处理Exception.class的异常
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e) {
        e.printStackTrace();
        return Result.fail(-1,e.getMessage());
    }

    @ExceptionHandler(BaseException.class)
    public Result doBaseException(BaseException e) {
        return Result.fail(e.getCode(),e.getMessage());
    }
}
